package com.tensquare.qa.service;

import com.tensquare.qa.dao.ProblemDao;
import com.tensquare.qa.pojo.Problem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import util.IdWorker;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 服务层
 * 
 * @author Administrator
 *
 */
@Service
public class ProblemService {

	@Autowired
	private ProblemDao problemDao;

	@Autowired
	private IdWorker idWorker;

	/**
	 * 根据标签 id 查询最新问题列表
	 * @param labelid
	 * @param page
	 * @param size
	 * @return
	 */
	public Page<Problem> newlist(String labelid, int page, int size) {
		Pageable pageable = PageRequest.of(page - 1, size);
		return problemDao.newList(labelid, pageable);
	}

	/**
	 * 根据 ID 查询热门问题列表
	 * @param labelid
	 * @param page
	 * @param size
	 * @return
	 */
	public Page<Problem> hotlist(String labelid, int page, int size){
		Pageable pageable = PageRequest.of(page-1, size);
		return problemDao.hotList(labelid, pageable);
	}

	/**
	 * 等待问答
	 * @param labelid
	 * @param page
	 * @param size
	 * @return
	 */
	public Page<Problem> waitlist(String labelid, int page, int size){
		Pageable pageable = PageRequest.of(page-1, size);
		return problemDao.waitList(labelid, pageable);
	}
}